package net.mingsoft.config;

import com.alibaba.druid.support.http.*;
import org.springframework.boot.web.servlet.*;
import javax.servlet.*;
import org.springframework.context.annotation.*;
import org.springframework.boot.autoconfigure.condition.*;
import com.alibaba.druid.support.spring.stat.*;
import org.springframework.aop.support.*;
import org.springframework.aop.*;
import org.aopalliance.aop.*;

@Configuration
public class DruidConfig
{
    @Bean
    @ConditionalOnProperty(prefix = "spring", name = { "datasource.druid.stat-view-servlet.enabled" }, havingValue = "true")
    public FilterRegistrationBean druidStatFilter() {
        final FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean((Filter)new WebStatFilter(), new ServletRegistrationBean[0]);
        filterRegistrationBean.addUrlPatterns(new String[] { "/*" });
        filterRegistrationBean.addInitParameter("exclusions", "/static/*,*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid,/druid/*");
        filterRegistrationBean.addInitParameter("principalSessionName", "username");
        return filterRegistrationBean;
    }
    
    @Bean
    @ConditionalOnProperty(prefix = "spring", name = { "datasource.druid.stat-view-servlet.enabled" }, havingValue = "true")
    public DruidStatInterceptor druidStatInterceptor() {
        return new DruidStatInterceptor();
    }
    
    @Bean
    @ConditionalOnProperty(prefix = "spring", name = { "datasource.druid.stat-view-servlet.enabled" }, havingValue = "true")
    public JdkRegexpMethodPointcut druidStatPointcut() {
        final JdkRegexpMethodPointcut druidStatPointcut = new JdkRegexpMethodPointcut();
        final String patterns = "net.mingsoft.*.biz.*";
        druidStatPointcut.setPatterns(new String[] { patterns });
        return druidStatPointcut;
    }
    
    @Bean
    @ConditionalOnProperty(prefix = "spring", name = { "datasource.druid.stat-view-servlet.enabled" }, havingValue = "true")
    public Advisor druidStatAdvisor() {
        return (Advisor)new DefaultPointcutAdvisor((Pointcut)this.druidStatPointcut(), (Advice)this.druidStatInterceptor());
    }
    
    static {
        System.setProperty("druid.mysql.usePingMethod", "false");
    }
}
